package com.example.photograph.controller;

import com.example.photograph.common.annotation.Log;
import com.example.photograph.common.core.controller.BaseController;
import com.example.photograph.common.core.domain.AjaxResult;
import com.example.photograph.common.core.page.TableDataInfo;
import com.example.photograph.common.enums.BusinessType;
import com.example.photograph.common.utils.poi.ExcelUtil;
import com.example.photograph.domain.SysEmployment;
import com.example.photograph.domain.SysUser;
import com.example.photograph.service.ISysEmploymentService;
import com.example.photograph.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 功能描述：
 *
 * @Author： phm
 * @Date： 2021-05-01 21:13
 */
@Controller
@RequestMapping("/photograph/myemployment")
public class SysMyEmploymentController extends BaseController
{
    private String prefix = "photograph/myemployment";

    @Autowired
    private ISysEmploymentService sysEmploymentService;

    @GetMapping()
    public String employment()
    {
        return prefix + "/myemployment";
    }

    /**
     * 查询就业信息管理列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysEmployment sysEmployment)
    {
//        startPage();
        SysUser sysUser = ShiroUtils.getSysUser();
        sysEmployment.setUserId(sysUser.getUserId());
        List<SysEmployment> list = sysEmploymentService.selectMySysEmploymentList(sysEmployment);
        return getDataTable(list);
    }

    /**
     * 导出就业信息管理列表
     */

    @Log(title = "就业信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysEmployment sysEmployment)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        sysEmployment.setUserId(sysUser.getUserId());
        List<SysEmployment> list = sysEmploymentService.selectSysEmploymentList(sysEmployment);
        ExcelUtil<SysEmployment> util = new ExcelUtil<SysEmployment>(SysEmployment.class);
        return util.exportExcel(list, "就业信息管理数据");
    }

    /**
     * 新增就业信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存就业信息管理
     */

    @Log(title = "就业信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysEmployment sysEmployment)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        sysEmployment.setUserId(sysUser.getUserId());
        return toAjax(sysEmploymentService.insertSysEmployment(sysEmployment));
    }

    /**
     * 修改就业信息管理
     */
    @GetMapping("/edit/{myemploymentId}")
    public String edit(@PathVariable("myemploymentId") Long myemploymentId, ModelMap mmap)
    {

        SysEmployment sysEmployment = sysEmploymentService.selectSysEmploymentById(myemploymentId);
        mmap.put("sysEmployment", sysEmployment);
        return prefix + "/edit";
    }

    /**
     * 修改保存就业信息管理
     */

    @Log(title = "就业信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysEmployment sysEmployment)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        sysEmployment.setUserId(sysUser.getUserId());
        return toAjax(sysEmploymentService.updateSysEmployment(sysEmployment));
    }

    /**
     * 删除就业信息管理
     */
    @Log(title = "就业信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysEmploymentService.deleteSysEmploymentByIds(ids));
    }
}
